package pl.pelcra.cesar.spider.webcrawler.interfaces;

import java.util.HashMap;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import edu.uci.ics.crawler4j.crawler.Page;
import edu.uci.ics.crawler4j.parser.HtmlParseData;
import edu.uci.ics.crawler4j.url.WebURL;

/**
 * interface to implement some actions to process page
 * 
 * @author margielewski
 * 
 */
public interface IPageActions {

	/**
	 * last action during processing page
	 * 
	 * @param webTask
	 *            actual webTask which is processed
	 * @param page
	 *            page object
	 * @param htmlParseData
	 *            page content as HtmlParseData object
	 */
	public void afterProcessPage(WebTask webTask, Page page,
			HtmlParseData htmlParseData);

	/**
	 * first action after get page content
	 * 
	 * @param htmlParseData
	 *            page content as HtmlParseData object
	 */
	public void beforeProcessPage(HtmlParseData htmlParseData);

	/**
	 * filtering urls from current page
	 * 
	 * @param webURL
	 *            current webUrl to check condition
	 * @param webTask
	 *            current webTask of processing page
	 * @return return true if url is satisfies the conditions otherwise return
	 *         false
	 */
	public boolean filterUrl(WebURL webURL, WebTask webTask);

	/**
	 * 
	 * @param webTask
	 *            current webTask of processing page
	 */
	public void finishProcessWebTasks(WebTask webTask);

	/**
	 * return WebURL for next parallel page
	 * 
	 * @param filterRules
	 *            filter rules to check urls
	 * @param listWebUrl
	 *            list of webUrls
	 * @return return next parallel webUrl
	 */
	public WebURL getFilterParallelWebUrl(FilterRules filterRules,
			List<WebURL> listWebUrl);

	/**
	 * 
	 * @return return http request method
	 */
	public HttpRequestMethod getHttpRequestMethod();

	/**
	 * return list BasicNameValuePair
	 * 
	 * @param mapParameters
	 *            mapParameters like map key-value from configuration file
	 * @return return list BasicNameValuePair
	 */
	public List<BasicNameValuePair> getParameterValuePairs(
			HashMap<String, String> mapParameters);

	/**
	 * 
	 * @return return true if cookie is required otherwise false
	 */
	public boolean isCookieRequired();

	/**
	 * 
	 * @param webTask
	 *            current webTask
	 * @param currentParallelWebUrl
	 *            current parallel webUrl
	 * @param filterParallelWebUrl
	 *            rules to filter parallel webUrls
	 * @return return true if next parallel page exists otherwise false
	 */
	public boolean isNextParallelPage(WebTask webTask,
			WebURL currentParallelWebUrl, WebURL filterParallelWebUrl);

	/**
	 * 
	 * @return return true if page is processed in parallel process otherwise
	 *         return false
	 */
	public boolean isParallelProcess();

	/**
	 * do some actions with all filtered urls
	 * 
	 * @param webTask
	 *            current webTask
	 */
	public void processListURLs(WebTask webTask);
}
